package com.example.administrator.yuejian2.model;

import com.example.administrator.yuejian2.RetrofitListener.RetrofitListener;
import com.example.administrator.yuejian2.bean.TrainBean;
import com.example.administrator.yuejian2.bean.TrainOrderBean;
import com.example.administrator.yuejian2.service.MyTrainOrderDetailService;
import com.example.administrator.yuejian2.service.TrainService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

import static com.example.administrator.yuejian2.other.Url.BASEURL;
import static com.example.administrator.yuejian2.other.Url.URL1;

public class TrainModel{

  private Retrofit retrofit;
    private TrainService trainService;


    public TrainModel ()
    {
        retrofit=new Retrofit.Builder()
                .baseUrl(BASEURL+URL1)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        trainService=retrofit.create(TrainService.class);
    }


    public void getTrainList(final RetrofitListener listener)
    {
        Call<List<TrainBean>> call=trainService.getTrainList();
        call.enqueue(new Callback<List<TrainBean>>() {
            @Override
            public void onResponse(Call<List<TrainBean>> call, Response<List<TrainBean>> response) {
                listener.onSuccess(response.body(),1);
            }

            @Override
            public void onFailure(Call<List<TrainBean>> call, Throwable t) {
                listener.onFail();
            }
        });
    }
}
